package com.example.homegallerie;

import java.io.IOException;
import com.example.homegallerie.R.drawable;
import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class tri extends Activity {
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.triptychons);

		final ImageView IVaudio = (ImageView) findViewById(R.id.IVaudio);
		final MediaPlayer mp = new MediaPlayer();
		final String lang = language.getLanguage();
		language.updateLanguage(this, lang);
		
		mp.setOnCompletionListener(new OnCompletionListener() {

            public void onCompletion(MediaPlayer mp) {
            	IVaudio.setImageResource(drawable.audio);
            	mp.reset();
            }
        });

		IVaudio.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				if (mp.isPlaying()) {
					IVaudio.setImageResource(drawable.audio);
					mp.stop();
					mp.reset();
				} else {
					if (lang == "de") {
						try {
							IVaudio.setImageResource(drawable.audios);
							AssetFileDescriptor afd;
							afd = getAssets().openFd("audioger.m4a");
							mp.setDataSource(afd.getFileDescriptor(),
									afd.getStartOffset(), afd.getLength());
							mp.prepare();
							mp.start();
						} catch (IllegalStateException e) {
							e.printStackTrace();
						} catch (IOException e) {
							e.printStackTrace();
						}
					} else {
						try {
							IVaudio.setImageResource(drawable.audios);
							AssetFileDescriptor afd;
							afd = getAssets().openFd("audioeng.m4a");
							mp.setDataSource(afd.getFileDescriptor(),
									afd.getStartOffset(), afd.getLength());
							mp.prepare();
							mp.start();
						} catch (IllegalStateException e) {
							e.printStackTrace();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}
				}
			}
		});
	}

	public void onBackPressed(){
	    super.onBackPressed();
	    finish();
	}
}


